aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/routes/bots/[bot_id].svelte
blob: 1d7994d64fabd404b6ceaf21ddcfa619486998d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<script lang="ts" context="module">
  import { get_session_token } from "$lib/auth";

  export async function load({ page }) {
    const token = get_session_token();
    const res = await fetch(`/api/bots/${page.params["bot_id"]}`, {
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${token}`,
      },
    });

    if (res.ok) {
      return {
        props: {
          bot: await res.json(),
        },
      };
    }

    return {
      status: res.status,
      error: new Error("Could not load bot"),
    };
  }
</script>

<script lang="ts">
  export let bot: object;

  let files;

  async function submitCode() {
    console.log("click");
    const token = get_session_token();

    const formData = new FormData();
    formData.append("File", files[0]);

    const res = await fetch(`/api/bots/${bot["id"]}/upload`, {
      method: "POST",
      headers: {
        // the content type header will be set by the browser
        "Authorization": `Bearer ${token}`,
      },
      body: formData,
    });

    console.log(res.statusText);
  }
</script>

<div>
  {bot["name"]}
</div>


<div>Upload code</div>
<form on:submit|preventDefault={submitCode}>
  <input type="file" bind:files/>
  <button type="submit">Submit</button>
</form>